package com.lzp.badminton.config;

import com.lzp.badminton.util.RedisSessionInterceptor;
import com.lzp.badminton.util.loginUtil.UserInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebSecurityConfig implements WebMvcConfigurer {
    @Bean
    public UserInterceptor  getUserInterceptor() {
        return new UserInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //所有已api开头的访问都要进入RedisSessionInterceptor拦截器进行登录验证，并排除login接口(全路径)。必须写成链式，分别设置的话会创建多个拦截器。
        //必须写成getSessionInterceptor()，否则SessionInterceptor中的@Autowired会无效
        registry.addInterceptor(getUserInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(
//                        "/**"
                        "/user/login",
                        "/user/logout",
                        "/user/isUserLogin",
                        "/user/verifyCode",
                        "/user/register",
                        "/user/getUserExit",
                        "/user/getUserAvatar",
                        "/activity/getActivityInfo",
                        "/activity/getActivityInfoById",
                        "/activityjoin/getActivityJoin",
                        "/activityjoin/getJoinActivityUser",
                        "/activityjoin/getJoinNum",
                        "/clubmember/getClubMember",
                        "/clubmember/getClubMemberInfo",
                        "/club/getClubInfo"
                );
    }
}